home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / lib / udev / entropykey.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2011-08-10  |  1.6 KB  |  54 lines

  1. #!/bin/sh
  2. #
  3. # Entropy key udev helper, ensures ekeyd is updated with new devices
  4. #
  5. # Copyright 2009-2011 Simtec Electronics
  6. #
  7. # For licence terms refer to the COPYING file.
  8.  
  9. BINPATH=/usr/sbin
  10.  
  11. # This function waits for the USB dev nodes to be made before
  12. # attempting to allow the ULUSBD to attach, this might resolve
  13. # a race condition where udev runs us before the nodes are
  14. # available.
  15. wait_for_usb () {
  16.   COUNTER=0
  17.   while ! test -e /dev/bus/usb/${BUSNUM}/${DEVNUM}; do
  18.     sleep 1
  19.     COUNTER=$(( ${COUNTER} + 1 ))
  20.     test ${COUNTER} -ge 10 && exit 1
  21.   done
  22.   $BINPATH/ekey-ulusbd -b${BUSNUM} -d${DEVNUM} -P/var/run/ekey-ulusbd-${ENTROPY_KEY_SERIAL}.pid -p/var/run/entropykeys/${ENTROPY_KEY_SERIAL} -D
  23.   sleep 1
  24.   $BINPATH/ekeydctl ${ACTION} /var/run/entropykeys/${ENTROPY_KEY_SERIAL}
  25.   exit 0
  26. }
  27.  
  28. if test "x$SUBSYSTEM" = "xtty"; then
  29.   # Update ekeyd with device operation
  30.   $BINPATH/ekeydctl ${ACTION} /dev/entropykey/${ENTROPY_KEY_SERIAL}
  31. else
  32.   if test "x$ACTION" = "xadd"; then
  33.     # start userland USB connection daemon
  34.     if test "x${BUSNUM}" = "x" -o "x${DEVNUM}" = "x"; then
  35.       exit 0
  36.     fi
  37.     if test -r "/var/run/ekey-ulusbd-${ENTROPY_KEY_SERIAL}.pid"; then
  38.       kill $(cat "/var/run/ekey-ulusbd-${ENTROPY_KEY_SERIAL}.pid") || true
  39.     fi
  40.     mkdir -p /var/run/entropykeys
  41.     wait_for_usb &
  42.     exit 0
  43.   fi
  44.   # Update ekeyd with device operation
  45.   $BINPATH/ekeydctl ${ACTION} /var/run/entropykeys/${ENTROPY_KEY_SERIAL}
  46.   if test "x$ACTION" = "xremove"; then
  47.     rm "/var/run/ekey-ulusbd-${ENTROPYKEY_KEY_SERIAL}.pid"
  48.     rm "/var/run/entropykeys/${ENTROPYKEY_KEY_SERIAL}"
  49.   fi
  50. fi
  51.  
  52. exit 0
  53.  
  54.